#!/bin/bash

# CNB_VSCODE_PROXY_URI
echo "# endpoints" >> CNB_VSCODE_PROXY_URI
echo "$CNB_VSCODE_PROXY_URI" >> CNB_VSCODE_PROXY_URI
mkdir -p ./logs

# nginx webDAV 浏览器可浏览全部文件，webDAV 客户端不支持查看 . 开头的文件/文件夹
nginx
echo "# nginx-webdav endpoint" >> CNB_VSCODE_PROXY_URI
echo "$CNB_VSCODE_PROXY_URI" | sed "s/{{port}}/4450/" >> CNB_VSCODE_PROXY_URI
echo "http://127.0.0.1:4450" >> CNB_VSCODE_PROXY_URI
echo "win mount" >> CNB_VSCODE_PROXY_URI
echo 'net use Z: "\\localhost@4450\DavWWWRoot"' >> CNB_VSCODE_PROXY_URI
echo "win unmount" >> CNB_VSCODE_PROXY_URI
echo 'net use Z: /delete /y' >> CNB_VSCODE_PROXY_URI
echo "taskkill /f /im explorer.exe" >> CNB_VSCODE_PROXY_URI
echo "start explorer.exe" >> CNB_VSCODE_PROXY_URI

# reclone webDAV 支持全部文件
nohup rclone serve webdav /workspace --addr :4451 --vfs-cache-mode full -L > ./logs/rclone.log 2>&1 &
echo "# rclone-webdav endpoint" >> CNB_VSCODE_PROXY_URI
echo "$CNB_VSCODE_PROXY_URI" | sed "s/{{port}}/4451/" >> CNB_VSCODE_PROXY_URI
echo "http://127.0.0.1:4451" >> CNB_VSCODE_PROXY_URI
echo "win mount" >> CNB_VSCODE_PROXY_URI
echo 'net use Z: "\\localhost@4451\DavWWWRoot"' >> CNB_VSCODE_PROXY_URI
echo "win unmount" >> CNB_VSCODE_PROXY_URI
echo 'net use Z: /delete /y' >> CNB_VSCODE_PROXY_URI
echo "taskkill /f /im explorer.exe" >> CNB_VSCODE_PROXY_URI
echo "start explorer.exe" >> CNB_VSCODE_PROXY_URI

